﻿using System.Collections.Generic;
using System.Data.Common;
using System.Dynamic;

namespace PKTools.Database
{
    public class SqlDynamic : DynamicObject
    {
        readonly Dictionary<string, object>
            values;

        public SqlDynamic(DbDataReader reader)
        {
            this.values = new Dictionary<string, object>();

            for (int i = 0; i < reader.FieldCount; i++)
                this.values.Add(reader.GetName(i), reader[i]);
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            return this.values.TryGetValue(binder.Name, out result);
        }
    }
}
